package com.bingguo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

@Configuration
@EnableWebFluxSecurity
public class WebFluxSecurityConfig {

    @Autowired
    private UrlProperties urlProperties;

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
//        HttpStatusServerEntryPoint entryPoint = new HttpStatusServerEntryPoint(HttpStatus.FORBIDDEN);
//        ServerHttpSecurity.AuthorizeExchangeSpec registry = http.csrf().disable()
//                .formLogin().disable()
//                .httpBasic().disable()
//                .logout().disable()
//                .headers()
//                .frameOptions()
//                .disable()
//                .and()
//                .cors().and()
//                .exceptionHandling()
//                .authenticationEntryPoint(entryPoint).and()
//                .authorizeExchange();
//        //放行白名单
//        urlProperties.permitAll(registry);
//        // 除白名单的请求需要鉴权认证
//        registry.anyExchange().authenticated();
//        return http.build();
        return http
                .authorizeExchange()
                .pathMatchers("/**").permitAll()
                .anyExchange().authenticated()
                .and().csrf().disable().build();
    }
}
